package cn.bookcycle.panda.pay.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.bookcycle.panda.pay.util.Response;
import cn.bookcycle.panda.pay.util.ServiceResponse;

/**
 * 处理回调请求的controller
 *
 * @author liufenglin
 * @date 2018年2月1日
 */
@Controller
public class NotifyController {
	private static final Logger logger = LoggerFactory.getLogger(NotifyController.class);
	@RequestMapping(value = "notify")
	public String getnotify(@RequestBody (required=false) String requestBody) {
		logger.warn("回调信息已经收到：{}", requestBody);
		// 启动一个线程来进行回调，以免耽搁回复微信接口信息的时间，引起微信发送多次通知
		ServiceResponse serviceResponse = new ServiceResponse(requestBody);
		Thread thread = new Thread(serviceResponse);
		// 开启线程
		thread.start();
		// 给微信返回信息
		return Response.returnSuccess();
	}
}
